<template>
  <div class="application-table">
    <div class="flex align-center justify-content-space-between" style="margin-bottom: 20px">
        <div class="title">党费使用申请</div>
        <el-button  type="primary" icon="Plus" @click="openDialog">新增申请</el-button>
    </div>
    <el-table :data="applications"  style="width: 100%">
      <el-table-column prop="applyRemarks" label="申请事项" align="center" />
      <el-table-column prop="applyMoney" label="申请金额" align="center">
        <template #default="{ row }">
          <div> ￥{{row.applyMoney}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="申请支部" align="center">
        <template #default="{ row }">
          <div >{{row.pbCommittee.committeeName}}</div>
        </template>
      </el-table-column>

      <el-table-column prop="applyTime" label="申请时间" align="center" />
      <el-table-column prop="status" label="审批状态" align="center">
        <template #default="{ row }">
          <div :class="getStatusClass(row.applyState)">
            {{ getStatusText(row.applyState) }}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template #default="{ row }">
          <el-button link type="primary" @click="viewDetail(row)">查看</el-button>
          <el-button link @click="cancelApplication(row)">撤销</el-button>
        </template>
      </el-table-column>
    </el-table>

    <PartyFeeUseApplyDialog v-model:visible="applyDialogVisible" :branch-options="branchOptions"  @confirm="handleConfirm" />
  </div>
</template>

<script setup>
import { ElButton } from 'element-plus'
import 'element-plus/dist/index.css'
import { Search,Plus } from '@element-plus/icons-vue'
import { getPBFeeApply} from "@/api/cost/cost.js";
import {ref} from "vue";
import {getPBCommitteeList} from "@/api/partyMemberInfo/partyMemberInfo.js";
import PartyFeeUseApplyDialog from './PartyFeeUseApplyDialog.vue'
const applications = ref([]);
const getStatusText = (status) => {
  switch (status) {
    case 0:
      return '审批中';
    case 1:
      return '已同意';
    case 2:
      return '已拒绝';
    default:
      return '未知审批状态';
  }
};
const getStatusClass = (status) => {
  switch (status) {
    case 0: // 未缴费
      return 'status-unpaid';
    case 1: // 部分缴费
      return 'status-partial';
    case 2: // 已缴费
      return 'status-paid';
    default:
      return '';
  }
};

const viewDetail = (row) => {
  console.log('查看详情:', row);
};

const cancelApplication = (row) => {
  console.log('撤销申请:', row);
};

const branchOptions = ref([]);

const applyDialogVisible = ref(false); // 变量名同步修改

// 获取申请党费数据
const  getFeeApplyList= async () => {
  let result = await getPBFeeApply();
  let data = result.data.data;
  if (result.status == 200 && result.data.code == 200){
    applications.value = data;
  }
}
const openDialog = () => {
  applyDialogVisible.value = true
}

// 获取支部信息
const getPBCommittee = async () => {
  let result = await getPBCommitteeList();
  let data = result.data.data;
  if (result.status == 200 && result.data.code == 200){
    branchOptions.value = data
  }
}

const handleConfirm = (formData) => {
  getFeeApplyList()
}



getFeeApplyList()
getPBCommittee();



</script>

<style scoped lang="scss">
.application-table {
  margin-top: 20px;
  padding:20px 20px 40px 20px;
  background-color: #FFFFFF;
  border-radius: 10px;
  .title {
    font-size: 18px;
    color: #333333;
    font-weight: bolder;
  }
  .status-unpaid {
    background-color: #FEE2E2;
    color: #A12C2C;
    width: fit-content;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bolder;
    margin: 0 auto;
  }
  .status-partial {
    background-color: #FEF9C3;
    color: #A27639;
    width: fit-content;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bolder;
    margin: 0 auto;
  }
  .status-paid {
    background-color: #DCFCE7;
    color: #2E7749;
    width: fit-content;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bolder;
    margin: 0 auto;
  }
}

</style>
